package com.um.jdy.platform.recharge.controller;

import com.um.jdy.common.member.entity.dto.RechargePackageDTO;
import com.um.jdy.common.member.entity.po.RechargePackage;
import com.um.jdy.common.member.entity.vo.RechargePackageVO;
import com.um.jdy.platform.recharge.entity.dto.PackagePageDTO;
import com.um.jdy.platform.recharge.entity.dto.RechargeOrderPageDTO;
import com.um.jdy.platform.recharge.entity.dto.RefundDTO;
import com.um.jdy.platform.recharge.entity.vo.RechargeOrderItemVO;
import com.um.jdy.platform.recharge.manager.RechargeOrderManager;
import com.um.jdy.platform.recharge.manager.RechargePackageManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseCMSManager;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 充值套餐
 *
 * @author cs
 * 日期 2023/5/25
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "充值订单")
@Validated
@RestController
@RequestMapping("/api/v1/cms/recharge/package")
@ApiPermission("recharge_package")
@TokenRequired
public class RechargePackageController extends BaseController<RechargePackageManager> {

    /**
     * 分页查询订单
     *
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询订单")
    @PostMapping("page")
    public Response<Page<RechargePackageVO>> page(@RequestBody PackagePageDTO params) {
        PageParams pageParams = params.toPageParams(new String[]{"name"},new String[]{"name"});
        pageParams.getCondition().put("orderby","sort_no asc");
        return manager.page(pageParams);
    }

    @ApiPermission("add")
    @ApiOperation("新增")
    @PostMapping
    public Response<RechargePackage> add(@RequestBody RechargePackageDTO dto) {
        return manager.addEntity(dto);
    }

    @ApiPermission("update")
    @ApiOperation("更新")
    @PutMapping({"{id}"})
    public Response<RechargePackage> update(@PathVariable String id, @RequestBody RechargePackageDTO dto) {
        return manager.updateEntity(id, dto);
    }

    @ApiPermission("delete_all")
    @ApiOperation("批量删除")
    @DeleteMapping
    public Response<Object> deleteIds(@ApiParam(value = "删除的id",required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }

    @ApiPermission("delete")
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiPermission("enable")
    @ApiOperation("启用、禁用")
    @PutMapping({"{id}/enable"})
    public Response<Object> enable(@PathVariable String id, @RequestParam String enable) {
        return manager.enable(id, enable);
    }

}
